unit InputMessage;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxControls, cxLookAndFeels, cxLookAndFeelPainters,
  cxContainer, cxEdit, dxSkinsCore, dxSkinsDefaultPainters, Menus,
  StdCtrls, cxButtons, cxLabel, cxTextEdit, cxMaskEdit, cxDropDownEdit;

type
  TfrmInputMessage = class(TForm)
    edtInput: TcxComboBox;
    lblSend: TcxLabel;
    btnOK: TcxButton;
    btnCancel: TcxButton;
    procedure FormCreate(Sender: TObject);
    procedure btnOKClick(Sender: TObject);
    procedure edtInputPropertiesValidate(Sender: TObject;
      var DisplayValue: Variant; var ErrorText: TCaption;
      var Error: Boolean);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function GetInputMessage(Send: string = ''): WideString;

var
  frmInputMessage: TfrmInputMessage;

implementation

{$R *.dfm}

function GetInputMessage(Send: string = ''): widestring;
begin
  Result := '';
  if frmInputMessage = nil then
    frmInputMessage := TfrmInputMessage.Create(nil);
  if Send <> '' then
    frmInputMessage.Caption := Send;
  if frmInputMessage.ShowModal = mrOk then
    Result := Trim(frmInputMessage.edtInput.Text);
  FreeAndNil(frmInputMessage);
end;

procedure TfrmInputMessage.FormCreate(Sender: TObject);
var
  lsMsg: TStringList;
begin
  if not FileExists(ExtractFilePath(Application.ExeName) + 'ServerMsg.ini') then Exit;
  lsMsg := TStringList.Create;
  lsMsg.LoadFromFile(ExtractFilePath(Application.ExeName) + 'ServerMsg.ini');
  if lsMsg.Count > 0 then
  begin
    TcxComboBoxProperties(edtInput.Properties).Items.Clear;
    TcxComboBoxProperties(edtInput.Properties).Items.AddStrings(lsMsg);
  end;
end;

procedure TfrmInputMessage.btnOKClick(Sender: TObject);
begin
  TcxComboBoxProperties(edtInput.Properties).Items.SaveToFile(ExtractFilePath(Application.ExeName) + 'ServerMsg.ini');
end;

procedure TfrmInputMessage.edtInputPropertiesValidate(Sender: TObject;
  var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean);
begin
  if TcxComboBoxProperties(edtInput.Properties).Items.IndexOf(edtInput.Text) < 0 then
    TcxComboBoxProperties(edtInput.Properties).Items.Add(edtInput.Text);
end;

end.

